#include "musiclist.h"

MusicList::MusicList()
{
}

void MusicList::addMusicByUrl(const QList<QUrl> &urls)
{
    //过滤list中的url文件，保证是音频文件
    for(const auto& musicUrl : urls)
    {
        QMimeDatabase db;
        QMimeType mime = db.mimeTypeForFile(musicUrl.toLocalFile());
        if(mime.name() != "audio/mpeg" && mime.name() != "audio/flac") continue;
        //这里是满足音频文件的，添加到列表中
        MusicInfo musicInfo(musicUrl);
        musicList.push_back(musicInfo);
    }
}

MusicList::iterator MusicList::begin()
{
    return musicList.begin();
}

MusicList::iterator MusicList::end()
{
    return musicList.end();
}

MusicList::iterator MusicList::findMusicById(const QString &id)
{
    for(iterator it = begin();it != end();++it)
    {
        if(id == it->getMusicId()) return it;
    }
    return end();
}
